<template>
  <div class="bg">
    <div class="box">
      <div class="nav"></div>
      <div class="header">
        <van-cell-group>
          <van-cell title="姓名" v-model="username" />
        </van-cell-group>
        <van-cell-group>
          <van-cell title="手机号" v-model="mobile" />
        </van-cell-group>
        <van-cell-group>
          <van-cell title="证件号:" v-model="card" />
        </van-cell-group>
      </div>
      <div class="message">
        温馨提示:&nbsp;&nbsp;请确认以上证件信息为<span>您本人真实有效信息,</span>若为他人预定可在家庭档案中管理就诊人信息,<span>该微信号一旦绑定此证件信息将不再允许修改调整,</span>请认真操作,谢谢您的合作!
      </div>
      <div class="btn" @click="bindmsg()">确定,是我的信息</div>
    </div>
  </div>
</template>
<script>
import { Cell, CellGroup, Toast } from "vant";
import { getUserinfoApi } from "@/service/api.js";
import { bindWxopenidApi } from "@/service/api.js";

// import { Toast } from 'vant'
export default {
  name: "index",
  data() {
    return {
      token: "",
      userinfo: "",
      username: "",
      mobile: "",
      card: "",
      unid: "",
      id: "",
      openid: "",
      dingdan:"",
      jiankang:""
    };
  },
  components: {},
  created() {
    this.mobile = this.$route.query.mobile;
    this.username = this.$route.query.username;
    this.card = this.$route.query.card;
    this.openid = this.$route.query.openid;

    this.id = this.$route.query.id;
    console.log(this.mobile);
  },
  methods: {
    bindmsg() {
      this.unid = JSON.parse(localStorage.getItem("unid"));
      this.openid=JSON.parse(localStorage.getItem("openid"));
      bindWxopenidApi({
        id: this.id,
        wxOpenid: this.openid,
        unid: this.unid,
        source: 16,
      }).then((res) => {
        console.log(res);
        if(res.code==4001){
          Toast.fail(res.msg)
        }
        if (res.code == 4000) {
      window.localStorage.removeItem("name");
          this.token = res.data;
          // 存入token
          if (this.token) {
            let token = JSON.stringify(this.token);
            localStorage.setItem("token", token);
              this.$router.go(-3);
          }
        }
      });
    },
    //   bindWxopenidApi({
    //     id: this.id,
    //     wxOpenid: this.openid,
    //     unid: "123sdsdsdsds545454",
    //     source: 16,
    //   }).then((res) => {
    //     console.log(res);
    //     if (res.code == 4000) {
    //       // 成功
    //       this.token = res.data;
    //       // 存入token
    //       let token = JSON.stringify(this.token);
    //       localStorage.setItem("token", token);

    //       this.$router.push({
    //         name: "shore",
    //       });
    //     }
    //   });

    //   console.log(res.msg);
    //   // 匹配档案
    // } else if (res.code == 4001) {
    //   this.msg = res.msg;
    //   Toast({
    //     message: this.msg,
    //   });
    //   console.log(111);
    // 获取用户信息
    // getuserinfo() {
    //   getUserinfoApi({
    //     token: this.token,
    //   }).then((res) => {
    //     console.log(res);
    //     if (res.code == 4000) {
    //       // 成功
    //       this.userinfo = res.data;
    //     } else if (res.code == 4001) {
    //       this.msg = res.msg;
    //       // 失败
    //       Toast({
    //         message: this.msg,
    //       });
    //     } else if (res.code == 4002) {
    //       this.msg = res.msg;
    //       setTimeout(() => {
    //         this.$router.push({
    //           name: "login",
    //         });
    //       }, 1000);
    //     }
    //   });
    // },
    // goMine() {
    //   // 确定
    //   this.$router.push({
    //     name: "Mine",
    //   });
    // },
  },
};
</script>
<style lang="scss" scoped>
.bg {
  .box {
    .nav {
      height: 44px;
    }
    .header {
      margin-bottom: 10px;
    }
    .message {
      margin-left: 10px;
      margin-right: 10px;
      font-size: 15px;
      text-align: center;
      text-align: justify;
      margin-bottom: 40px;
      span {
        color: red;
      }
    }
    .btn {
      width: 300px;
      height: 40px;
      background: #07c6b4;
      border-radius: 5px;
      margin: 0 auto;
      text-align: center;
      line-height: 40px;
      font-size: 15px;
      color: #ffffff;
    }
  }
}
</style>